<template>
  <!-- ceshi1111111111 -->
  <div class="viewContain">
    <el-form :model="listQuery" size="small" label-width="100px">
      <el-row>
        <input type="hidden" value="listQuery.userId">
        <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 6 }" :xl="{ span: 6 }">
          <el-form-item label="设备编号" prop="equipmentNo">
            <el-input
              v-model="listQuery.equipmentNo"
              placeholder="请输入设备设备编号"
              clearable
              @keyup.enter.native="handleSearch"
            />
          </el-form-item>
        </el-col>
        <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 6 }" :xl="{ span: 6 }">
          <el-form-item label="设备状态" prop="state">
            <el-select v-model="listQuery.state" clearable placeholder="设备状态">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 5, offset: 1}" :xl="{ span: 6 }">
          <el-button size="mini" type="primary" @click="handleSearch">查询</el-button>
          <el-button size="mini" type="primary" plain @click="resetInput">重置</el-button>
        </el-col>
      </el-row>
    </el-form>
    <!-- 批量下载模板 -->
    <el-row>
      <el-col :xs="{ span: 24 }" :sm="{ span: 24 }" :md="{ span: 24 }" :xl="{ span: 24 }">
        <div style="float:right;">
          <el-button type="primary" size="mini" @click="showAddUI">新增</el-button>
          <el-button type="primary" size="mini" @click="getDownloadTemplate">下载批量注册模板</el-button>
          <el-button type="primary" size="mini" @click="regitstBatch">批量注册</el-button>
          <el-button type="primary" size="mini" @click="toRegistResult">查询批量注册结果</el-button>
        </div>
      </el-col>
    </el-row>
    <!-- 设备注册 -->
    <el-dialog :title="dialogTitle" :visible.sync="dialogVisble" width="900px" @close="getList">
      <el-form ref="formData" :model="formData" size="small" label-width="150px" :rules="rules">
        <el-row>

          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="所属机构 :" prop="orgId">
              <el-cascader
                v-model="formData.orgId"
                style="width:200px;"
                :options="orgs"
                clearable
                :props="casProps"
                @change="handleChange"
              />
            </el-form-item>
          </el-col>

          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="所属区域 :" prop="areaInfo">
              <el-input v-model="formData.areaInfo" placeholder="最多输入20字" clearable style="max-width:200px" disabled />
            </el-form-item>
          </el-col>

          <input type="hidden" name="areaCode" value="formData.areaCode">

          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="设备名称 :" prop="deviceName">
              <el-input v-model="formData.deviceName" size="small" clearable placeholder="设备名称" style="max-width:200px" />
            </el-form-item>
          </el-col>

          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="设备id(imei) :" prop="equipmentNo">
              <el-input v-if="dialogTitle==='新增设备'" v-model="formData.equipmentNo" size="small" clearable placeholder="设备id" style="max-width:200px" />
              <el-input v-if="dialogTitle==='修改设备'" v-model="formData.equipmentNo" disabled size="small" clearable placeholder="设备id" style="max-width:200px" />
            </el-form-item>
          </el-col>

          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="持有人 :" prop="owner">
              <el-input v-model="formData.owner" size="small" clearable placeholder="持有人" style="max-width:200px" />
            </el-form-item>
          </el-col>

          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="持有人联系方式 :" prop="ownerLink">
              <el-input v-model="formData.ownerLink" size="small" clearable placeholder="持有人联系方式" style="max-width:200px" />
            </el-form-item>
          </el-col>

          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="设备类型 :" prop="partkind">
              <el-select v-model="formData.partkind" style="width:200px;" clearable placeholder="设备类型">
                <el-option
                  v-for="item in partkinds"
                  :key="item.code"
                  :label="item.codeDesc"
                  :value="item.code"
                />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="设备ip :" prop="deviceIp">
              <el-input v-model="formData.deviceIp" size="small" clearable placeholder="设备ip" style="max-width:200px" />
            </el-form-item>
          </el-col>

          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="设备Mac :" prop="deviceMac">
              <el-input v-model="formData.deviceMac" size="small" clearable placeholder="设备Mac" style="max-width:200px" />
            </el-form-item>
          </el-col>

          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="设备状态 :" prop="state">
              <el-radio-group v-model="formData.state">
                <el-radio :label="'Y'">可用</el-radio>
                <el-radio :label="'W'">维护</el-radio>
                <el-radio :label="'T'">停用</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="金融功能 :" prop="isFinance">
              <el-radio-group v-model="formData.isFinance">
                <el-radio :label="1">是</el-radio>
                <el-radio :label="0">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="商户号 :" prop="tenantNo">
              <el-input v-model="formData.tenantNo" :disabled="financeFlag" size="small" clearable placeholder="商户号" style="max-width:200px" />
            </el-form-item>
          </el-col>
          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="终端号 :" prop="terminalNo">
              <el-input v-model="formData.terminalNo" :disabled="financeFlag" size="small" clearable placeholder="终端号" style="max-width:200px" />
            </el-form-item>
          </el-col>
          <el-col :xs="{ span: 24 }" :sm="{ span: 24 }" :md="{ span: 24 }" :xl="{ span: 24 }">
            <el-form-item>
              <el-button v-if="dialogTitle==='新增设备'" style="margin-left:200px;" size="mini" type="primary" @click="handleImportDevice">新增</el-button>
              <el-button v-if="dialogTitle==='修改设备'" style="margin-left:200px;" size="mini" type="primary" @click="handleUpdateDevice">修改</el-button>
              <el-button size="mini" type="primary" @click="handleBack">返回</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
    <!--数据列表-->
    <el-table
      ref="table"
      v-loading="loading"
      fit
      :data="tableData"
      border
      size="mini"
      style="margin-top:10px"
    >
      <el-table-column label="序号" align="center">
        <template slot-scope="scope">
          <span>{{ (listQuery.pageNo - 1) * listQuery.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="areaName" label="区域信息" align="center" width="200" />
      <el-table-column prop="createTime" label="注册时间" align="center" width="150" />
      <el-table-column prop="deviceIp" label="设备ip" align="center" width="115" />
      <el-table-column prop="deviceMac" label="设备mac" align="center" width="115" />
      <el-table-column prop="deviceName" label="设备名称" align="center" width="150" />
      <el-table-column prop="equipmentNo" label="设备id" align="center" width="150" />
      <el-table-column prop="orgName" label="网点信息" align="center" width="150" />
      <el-table-column prop="owner" label="持有人" align="center" />
      <el-table-column prop="ownerLink" label="持有人联系方式" align="center" width="150" />
      <el-table-column prop="partkind" label="设备类型" align="center" />
      <el-table-column prop="state" label="状态" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.state == '可用' ">可用</span>
          <span v-if="scope.row.state == '维护' ">维护</span>
          <span v-if="scope.row.state == '停用' ">停用</span>
        </template>
      </el-table-column>
      <el-table-column prop="updateTime" label="修改时间" align="center" width="150" />
      <el-table-column align="center" label="操作" width="120">
        <template slot-scope="scope">
          <el-button class="text-button" size="mini" @click="handleEditDevice(scope.row)">修改</el-button>
          <el-button class="text-button" size="mini" @click="showDeviceDetail(scope.row)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 详情 -->
    <el-dialog
      :title="deviceDialog"
      :visible.sync="dialogFormVisible_detail"
      :close-on-click-modal="false"
      width="800px"
    >
      <el-form :model="detailInfo" size="small" label-width="150px">
        <el-row>
          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="网点 :">
              {{ detailInfo.orgName }}
            </el-form-item>
          </el-col>
          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="设备ip :">
              {{ detailInfo.deviceIp }}
            </el-form-item>
          </el-col>
          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="设备mac :">
              {{ detailInfo.deviceMac }}
            </el-form-item>
          </el-col>
          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="设备名称 :">
              {{ detailInfo.deviceName }}
            </el-form-item>
          </el-col>
          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="设备id(imei) :">
              {{ detailInfo.equipmentNo }}
            </el-form-item>
          </el-col>
          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="设备类型 :">
              {{ detailInfo.partkind }}
            </el-form-item>
          </el-col>
          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="设备状态 :">
              {{ detailInfo.state }}
            </el-form-item>
          </el-col>
          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="区域信息 :">
              {{ detailInfo.areaName }}
            </el-form-item>
          </el-col>
          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="金融功能 :">
              {{ detailInfo.isFinance==1 ? '开启' : '关闭' }}
            </el-form-item>
          </el-col>
          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="商户号 :">
              {{ detailInfo.tenantNo }}
            </el-form-item>
          </el-col>
          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="终端号 :">
              {{ detailInfo.terminalNo }}
            </el-form-item>
          </el-col>
          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="持有人 :">
              {{ detailInfo.owner }}
            </el-form-item>
          </el-col>
          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="持有人联系方式 :">
              {{ detailInfo.ownerLink }}
            </el-form-item>
          </el-col>
          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="注册时间 :">
              {{ detailInfo.createTime }}
            </el-form-item>
          </el-col>
          <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 12 }" :xl="{ span: 12 }">
            <el-form-item label="修改时间 :">
              {{ detailInfo.updateTime }}
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" align="center">
        <el-button size="small" type="primary" @click="dialogFormVisible_detail=false">关闭</el-button>
      </div>
    </el-dialog>
    <pagination
      :total-count="totalCount"
      :page.sync="listQuery.pageNo"
      :limit.sync="listQuery.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<script>
import { validPhone } from '@u/validate'
import { commonMixin } from '@v/mixin/commonMixin.js'
import ComApiUrl from '@a/comomApi.js'
import pagination from '@/components/pagination/index.vue'
// eslint-disable-next-line no-unused-vars
import { register, downloadTemplate, regitstDevicesBatch, getDeviceKinds, getOrgList, getAreaInfo, getOrgById } from '@a/device/basic.js'
import { updateDeviceInfo } from '@a/device/basic.js'

export default {
  components: { pagination },
  mixins: [commonMixin],
  data() {
    const validatePhone = (rules, value, callback) => {
      if (!validPhone(value)) {
        callback(new Error('手机号格式输入有误!'))
      } else {
        callback()
      }
    }

    const validateFinace = (rules, value, callback) => {
      console.log('isfinance' + parseInt(value))
      if (parseInt(value) === 1) {
        console.log(this.formData.tenantNo + ', zdCode:' + this.formData.terminalNo)
        if (this.formData.tenantNo === undefined || this.formData.terminalNo === undefined || this.formData.tenantNo === '' || this.formData.terminalNo === '') {
          callback(new Error('选择金融功能后需要填写商户号与终端号!'))
        } else {
          callback()
        }
      } else {
        callback()
      }
    }

    return {
      comApiUrlList: new ComApiUrl('/device/api/v2/deviceInfo/list'),
      comApiUrlAdd: new ComApiUrl('/device/api/v2/deviceInfo/register'),
      comApiUrlUpdate: new ComApiUrl('/device/api/v2/deviceInfo/update'),
      loading: false,
      dialogVisble: false,
      dialogFormVisible_detail: false,
      currentPage: 1,
      financeFlag: true,
      partkinds: [],
      dialogTitle: '新增设备',
      formData: {},
      deviceDialog: '设备详情',
      listQuery: {
        pageSize: 10,
        pageNum: 1,
        userId: '',
        state: '',
        areaCode: '',
        equipmentNo: '',
        orgId: '0'
      },
      detailInfo: {
        areaName: '',
        createTime: '',
        deviceIp: '',
        deviceMac: '',
        deviceName: '',
        equipmentNo: '',
        id: '',
        orgId: '',
        orgName: '',
        owner: '',
        ownerLink: '',
        partkind: '',
        state: '',
        updateTime: '',
        isFinance: 1,
        tenantNo: '',
        terminalNo: ''
      },
      tableData: [],
      options: [
        {
          value: 'Y',
          label: '可用'
        },
        {
          value: 'W',
          label: '维护'
        },
        {
          value: 'T',
          label: '停用'
        }
      ],
      orgs: [],
      casProps: {
        checkStrictly: true, // 是否严格的遵守父子节点不互相关联
        emitPath: false, // 在选中节点改变时，是否返回由该节点所在的各级菜单的值所组成的数组，若设置 false，则只返回该节点的值
        value: 'orgId', // 指定选项的值为选项对象的某个属性值
        label: 'name' // 指定选项标签为选项对象的某个属性值
      },
      value: '',
      rules: {
        deviceName: [
          { required: true, message: '设备名不能为空', trigger: 'blur' }
        ],
        equipmentNo: [
          { required: true, message: '设备编号不能为空', trigger: 'blur' }
        ],
        orgId: [
          { required: true, message: '网点id不能为空', trigger: 'blur' }
        ],
        owner: [
          { required: true, message: '持有人不能为空', trigger: 'blur' }
        ],
        ownerLink: [
          { required: true, message: '持有人联系方式不能为空', trigger: 'blur' },
          { validator: validatePhone, trigger: 'blur' }
        ],
        partkind: [
          { required: true, message: '设备类型不能为空', trigger: 'blur' }
        ],
        state: [
          { required: true, message: '请选择设备状态', trigger: 'blur' }
        ],
        isFinance: [
          { validator: validateFinace, trigger: 'blur' }
        ]
      },
      userId: ''
    }
  },
  watch: {
    'formData.isFinance'(val) {
      if (parseInt(val) === 1) {
        this.financeFlag = false
      }
      if (parseInt(val) === 0) {
        this.financeFlag = true
      }
    }
  },
  mounted() {
    const userInfo = JSON.parse(localStorage.getItem('userInfo'))
    this.userId = userInfo.userId
    getDeviceKinds().then(res => {
      console.log(res)
      if (res.code === 0) {
        this.partkinds = res.data
      } else {
        this.$message({
          type: 'error',
          message: res.msg
        })
      }
    })
    getOrgList(userInfo.areaId).then(res => {
      if (res.code === 0) {
        this.orgs = res.data
        console.log(this.orgs)
      }
    })
    this.getList()
  },
  methods: {

    // 重置查询输入框中的值
    resetInput() {
      this.listQuery.equipmentNo = ''
      this.listQuery.state = ''
      this.getList()
    },

    // 查询,显示所有设备信息
    getList() {
      this.listQuery.userId = this.userId
      this.getInfo()
    },

    // 条件查询
    handleSearch() {
      this.listQuery.userId = this.userId
      this.getInfo()
    },

    // 修改信息
    handleEditDevice(row) {
      this.dialogVisble = true
      this.dialogTitle = '修改设备'
      console.log(row.orgId)
      console.log(this.orgs)
      var rowState = ''
      if (row.state === '可用') { rowState = 'Y' }
      if (row.state === '维护') { rowState = 'W' }
      if (row.state === '停用') { rowState = 'T' }
      console.log('rowState：' + rowState)
      this.$nextTick(() => {
        this.formData = row
        this.formData.state = rowState
        this.formData.createTime = ''
        this.formData.updateTime = ''
      })
      this.getDistinct(row.orgId)
    },

    handleUpdateDevice() {
      console.log('修改设备信息')
      this.$refs.formData.validate(valide => {
        valide ? this.updateDevice() : ''
      })
    },

    // 修改设备信息
    updateDevice() {
      for (var i = 0; i < this.partkinds.length; i++) {
        if (this.formData.partkind === this.partkinds[i].codeDesc) {
          this.formData.partkind = this.partkinds[i].code
          break
        }
      }
      if (this.financeFlag === true) {
        this.formData.tenantNo = ''
        this.formData.terminalNo = ''
      }

      updateDeviceInfo(this.formData).then(res => {
        console.log(res)
        if (res.code === 0) {
          this.$message({
            type: 'success',
            message: '设备更新成功'
          })
          this.dialogVisble = false
          this.$refs.formData.resetFields()
          this.getList()
        } else {
          this.$message({
            type: 'error',
            message: res.msg
          })
        }
      })
    },

    handleBack() {
      this.dialogVisble = false
      this.$refs.formData.resetFields()
      this.getList()
    },

    // 显示注册页面，准备数据
    showAddUI() {
      this.$nextTick(() => {
        this.$refs.formData.resetFields()
      })
      this.dialogVisble = true
      this.dialogTitle = '新增设备'
      getDeviceKinds().then(res => {
        console.log(res)
        if (res.code === 0) {
          this.partkinds = res.data
          const userInfo = JSON.parse(localStorage.getItem('userInfo'))
          this.formData.orgId = userInfo.orgId
          this.formData.areaCode = userInfo.areaId
          console.log('机构id： ' + this.formData.areaCode)
          getOrgList(userInfo.areaId).then(res => {
            if (res.code === 0) {
              this.orgs = res.data
              const distinctId = res.data[0].distinctId
              if (distinctId !== null || distinctId === undefined) {
                getAreaInfo(distinctId).then(res => {
                  if (res.code === 0) {
                    const arr = []
                    if (res.data !== null) {
                      res.data.forEach(item => arr.push(item.name))
                      console.log(arr)
                      console.log(arr.join('/'))
                      this.formData.areaInfo = arr.join('/')
                      this.$forceUpdate()
                    }
                  }
                })
              }
            }
          })
        } else {
          this.$message({
            type: 'error',
            message: res.msg
          })
        }
      })
    },

    // 设备注册
    handleImportDevice() {
      this.$refs.formData.validate(valide => {
        console.log(this.formData)
        // 新增和修改前检测金融功能是否开启 开启在提交时将其置空
        if (this.financeFlag === true) {
          this.formData.tenantNo = ''
          this.formData.terminalNo = ''
        }
        if (valide) {
          register(this.formData).then(res => {
            console.log(res)
            if (res.code === 0) {
              this.dialogVisble = false
              this.getList()
              this.$refs.formData.resetFields()
              this.$message({
                type: 'success',
                message: '设备新增成功'
              })
            } else {
              this.$message({
                type: 'error',
                message: res.msg
              })
            }
          })
        }
      })
    },

    // 下载批量注册模板
    getDownloadTemplate() {
      downloadTemplate(this.userId).then(res => {
        var blob = new Blob([res], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8' })
        var url = window.URL.createObjectURL(blob)
        var aLink = document.createElement('a')
        aLink.style.display = 'none'
        aLink.href = url
        aLink.setAttribute('download', 'excel.xls')
        document.body.appendChild(aLink)
        aLink.click()
        document.body.removeChild(aLink) // 下载完成移除元素
        window.URL.revokeObjectURL(url) // 释放掉blob对象
      })
    },

    // 批量注册
    regitstBatch() {
      var that = this
      const fileType = ['xls', 'xlsx'] // 限制文件上传类型
      const maxSize = 500 * 1024 // 限制文件大小
      const fileSelective = document.createElement('input')
      fileSelective.type = 'file'
      fileSelective.name = 'file'
      document.body.appendChild(fileSelective)
      // 选中文件确定后触发该事件
      fileSelective.onchange = function(e) {
        // 限制文件类型
        const file = e.target.files[0]
        const formData = new FormData()
        formData.append('file', file)
        const currentFileType = file.name.slice(file.name.lastIndexOf('.') + 1)
        if (!fileType.includes(currentFileType)) {
          that.$message({
            type: 'error',
            message: '只允许上传.xls,.xlsx类型的文件',
            duration: 3 * 1000
          })
          return ''
        }

        // 限制文件大小
        if (file.size > maxSize) {
          that.$message({
            type: 'error',
            message: '文件大小不得超出500k',
            duration: 3 * 1000
          })
          return ''
        }

        regitstDevicesBatch(formData, that.userId).then(res => {
          console.log(res)
          if (res.code === 0) {
            that.$message({
              type: 'success',
              message: res.data
            })
            that.getList()
          } else {
            that.$message({
              type: 'error',
              message: res.msg
            })
          }
        })
      }
      fileSelective.click()
      document.body.removeChild(fileSelective)
    },

    // 所属机构级联选择
    handleChange(orgId) {
      this.getDistinct(orgId)
    },
    // 获取所属区域信息
    getDistinct(orgId) {
      if (orgId !== null && orgId !== undefined) {
        getOrgById(orgId).then(res => {
          const distinctId = res.data.distinctId
          this.formData.areaCode = distinctId
          getAreaInfo(distinctId).then(res => {
            if (res.code === 0) {
              const arr = []
              if (res.data !== null) {
                res.data.forEach(item => arr.push(item.name))
                this.formData.areaInfo = arr.join('/')
                this.$forceUpdate()
              }
            }
          })
        })
      }
    },

    // 跳转到查询批量注册结果页面
    toRegistResult() {
      var id = this.listQuery.userId
      console.log('跳转到查询批量注册结果页面' + id)
      // 先准备表格数据
      this.$router.push({
        name: 'DeviceLogList',
        params: {
          userId: id
        }
      })
    },
    showDeviceDetail(data) {
      this.dialogFormVisible_detail = true
      this.detailInfo = data
    }
  }
}
</script>
